//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.fusheng.utils;

import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;

public class DpUtil {
    public DpUtil() {
    }

    public static int getScreenWidth(Context context) {
        return context == null ? Resources.getSystem().getDisplayMetrics().widthPixels : context.getResources().getDisplayMetrics().widthPixels;
    }

    public static int getScreenHeight(Context context) {
        return context == null ? Resources.getSystem().getDisplayMetrics().heightPixels : context.getResources().getDisplayMetrics().heightPixels;
    }

    public static int dp2px(float dpValue) {
        float scale = Resources.getSystem().getDisplayMetrics().density;
        return (int)(dpValue * scale + 0.5F);
    }

    public static float sp2px(float spValue) {
        float fontScale = Resources.getSystem().getDisplayMetrics().scaledDensity;
        return spValue * fontScale + 0.5F;
    }

    public static int px2dp(float pxValue) {
        float scale = Resources.getSystem().getDisplayMetrics().density;
        return (int)(pxValue / scale + 0.5F);
    }

    public static int px2sp(float pxValue) {
        float fontScale = Resources.getSystem().getDisplayMetrics().scaledDensity;
        return (int)(pxValue / fontScale + 0.5F);
    }

    public static float applyDimension(float value, int unit) {
        DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
        switch(unit) {
        case 0:
            return value;
        case 1:
            return value * metrics.density;
        case 2:
            return value * metrics.scaledDensity;
        case 3:
            return value * metrics.xdpi * 0.013888889F;
        case 4:
            return value * metrics.xdpi;
        case 5:
            return value * metrics.xdpi * 0.03937008F;
        default:
            return 0.0F;
        }
    }
}
